package com.qf.shop.service.impl;

import com.qf.shop.dao.GoodsDao;
import com.qf.shop.dao.Impl.GoodsDaoImpl;
import com.qf.shop.entity.Goods;
import com.qf.shop.entity.Page;
import com.qf.shop.service.GoodsService;
import com.qf.shop.utils.DruidUtils;

import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    private GoodsDao goodsDao = new GoodsDaoImpl();
    @Override
    public List<Goods> getAllGoodsById(Page page, int typeid) {
        List<Goods> goods = null;
        try {
            DruidUtils.begin();
            goods = goodsDao.selectAllByPage(page,typeid);
            page.setTotalCount((int)goodsDao.selectCount(typeid));
            DruidUtils.commit();
        } catch (Exception e) {
            DruidUtils.rollback();
            e.printStackTrace();
        }
        return goods;
    }

    @Override
    public Goods getGoodById(int id) {
        Goods goods = null;
        try {
            DruidUtils.begin();
            goods= goodsDao.selectGoods(id);
            DruidUtils.commit();
        } catch (Exception e) {
            DruidUtils.rollback();
            e.printStackTrace();
        }
        return goods;
    }
}
